package com.heng.test;

import java.lang.String;
import java.util.concurrent.locks.LockSupport;

public class LockSupportExample {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            // 创建一个阻塞器对象
            Object blocker = new Object();
            // 设置当前线程的阻塞器
            LockSupport.setCurrentBlocker(blocker);
            // 打印当前线程的阻塞器
            System.out.println("当前线程的阻塞器: " + LockSupport.getBlocker(Thread.currentThread()));
            // 线程休眠一段时间
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 清除当前线程的阻塞器
            LockSupport.setCurrentBlocker(null);
            // 再次打印当前线程的阻塞器
            System.out.println("清除阻塞器后，当前线程的阻塞器: " + LockSupport.getBlocker(Thread.currentThread()));
        });
        // 启动线程
        thread.start();
    }
}